//
//  DealInfoViewController.m
//  智积分
//
//  Created by apple on 2018/3/30.
//  Copyright © 2018年 Cynic. All rights reserved.
//

#import "DealInfoViewController.h"

@interface DealInfoViewController ()
@property (nonatomic ,retain)UIImageView *header;
@property (nonatomic ,retain)UILabel *name;
@property (nonatomic ,retain)UILabel *money;
@property (nonatomic ,retain)UILabel *status;
@property (nonatomic ,retain)UILabel *time;
@property (nonatomic ,retain)UILabel *number;
@property (nonatomic ,retain)UILabel *dealMoney;
@property (nonatomic ,retain)UILabel *weixinMoney;
@property (nonatomic ,retain)UILabel *integralMoney;
@property (nonatomic ,retain)UILabel *partPrice;
@property (nonatomic ,retain)UILabel *partCoin;
@property (nonatomic ,retain)NSDictionary *model;
@end

@implementation DealInfoViewController

-(void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    if (cx_hit == 812) {
        
    }
    else{
        [UIApplication sharedApplication].statusBarStyle = UIStatusBarStyleDefault;
    }
}

-(void)viewWillDisappear:(BOOL)animated{
    [super viewWillDisappear:animated];
    if (cx_hit == 812) {
        [UIApplication sharedApplication].statusBarStyle = UIStatusBarStyleLightContent;
    }
    else{
        [UIApplication sharedApplication].statusBarStyle = UIStatusBarStyleDefault;
    }
}

- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = bggrayColor;
//    [self viewLoad];
    // Do any additional setup after loading the view.
}

-(void)viewLoad{
    [self setNavigationViewWithTitle:@"订单详情" WithCanPop:YES WithPopData:@"black_return" WithPopisString:NO WithHasRightOperation:NO WithrightOperationData:@"" WithRightisString:YES WithNavigationColor:[UIColor whiteColor] withBgView:self.view];
    self.centerTitle.textColor = [UIColor blackColor];
    UIView *navilayer = [[UIView alloc] initWithFrame:CGRectMake(0, self.navigationView.bounds.size.height - 1, cx_wid, 1)];
    navilayer.backgroundColor = [[UIColor lightGrayColor] colorWithAlphaComponent:0.4]; 
    [self.navigationView addSubview:navilayer];
    [self MainViewLoad];
}

-(void)MainViewLoad{
    CGFloat topdis = cxsingler.topdis  + 44 + 29 + 68;
    UIView *topBg = [[UIView alloc] initWithFrame:CGRectMake(0, cxsingler.topdis  + 44, cx_wid, topdis + 140)];
    topBg.backgroundColor = [UIColor whiteColor];
    [self.view addSubview:topBg];
    
    
    _header = [[UIImageView alloc] init];
    _header.bounds = CGRectMake(0, 0, 68, 68);
    _header.center = CGPointMake(cx_wid / 2, cxsingler.topdis  + 44 + 29 + 34);
    _header.layer.cornerRadius = 34;
    _header.clipsToBounds = YES;
    _header.layer.borderWidth = 1;
    _header.layer.borderColor = [[UIColor lightGrayColor] colorWithAlphaComponent:0.4].CGColor;
    _header.backgroundColor =bggrayColor;
    [self.view addSubview:_header];
    
    
    //名字 金额变动 交易状态 初始化布局
    for (NSInteger index = 0; index < 3; index ++) {
        UILabel *label = [[UILabel alloc]init];
        label.bounds = CGRectMake(15, 0, cx_wid - 30, 25);
        if (index == 0) {
            _name = label;
            label.font = [UIFont systemFontOfSize:16];
            label.center = CGPointMake(cx_wid / 2, topdis + 30);
        }
        else if (index == 1){
            _money = label;
            label.font = [UIFont systemFontOfSize:36];
            label.bounds = CGRectMake(15, 0, cx_wid - 30, 30);
            label.center = CGPointMake(cx_wid / 2, topdis + 100);
        }
        else if (index == 2){
            _status = label;
            label.font = [UIFont systemFontOfSize:14];
            label.textColor = [CXSinglerModel colorWithHex:@"9B9B9B" alpha:1];
            label.center = CGPointMake(cx_wid / 2, topdis + 140);
        }
        label.textAlignment = NSTextAlignmentCenter;
        [self.view addSubview:label];
    }
    
    
    //两侧信息初始化布局
    NSArray *titles = @[@"",@"订单金额",@"微信支付",@"积分支付",@"其他抵扣"];
    for (NSInteger index = 0; index < titles.count; index ++) {
        UIView *partView = [[UIView alloc] initWithFrame:CGRectMake(0, topdis + 140 + 40 * (index + 1) , cx_wid, 40)];
        partView.backgroundColor = [UIColor whiteColor];
        UIView *layerView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, cx_wid, 1)];
        layerView.backgroundColor = [[UIColor lightGrayColor] colorWithAlphaComponent:0.4];
        [partView addSubview:layerView];
        

        
        UILabel *left = [[UILabel alloc] initWithFrame:CGRectMake(12, 10, cx_wid / 2, 20)];
        left.text = titles[index];
        left.font = [UIFont systemFontOfSize:14];
        UILabel *right = [[UILabel alloc] initWithFrame:CGRectMake(cx_wid / 2, 10, cx_wid / 2 - 12, 20)];
        left.textColor = [CXSinglerModel colorWithHex:@"666666" alpha:1];
        right.textColor = [UIColor blackColor];
        
        if (index == 0) {
            _time = left;
            _number = right;
        }
        else if (index == 1){
            _dealMoney = right;
        }
        else if (index == 2){
            _weixinMoney = right;
        }
        else if (index == 3){
            _integralMoney = right;
        }
        else if (index == 4){
            _partPrice = right;
        }
        [partView addSubview:left];
        [partView addSubview:right];
        right.textAlignment = NSTextAlignmentRight;
        [self.view addSubview:partView];
    }
    [self wrteinfo];
}



/**
 加载数据
 */
-(void)wrteinfo{
    [self loadlabel:_name WithEnd:[NSString stringWithFormat:@"%@",_model[@"userName"]] withresult:@"" withColor:[UIColor blackColor] withFont:14 withbaseColor:[UIColor blackColor]];
    NSString *timestr = [self gettimeByInter:[[[NSString stringWithFormat:@"%@",_model[@"createTime"]] substringWithRange:NSMakeRange(0, 10)] integerValue]];
    [self loadlabel:_time WithEnd:timestr withresult:@"" withColor:[UIColor blackColor] withFont:13 withbaseColor:[CXSinglerModel colorWithHex:@"9A9A9A" alpha:1]];
    [self loadlabel:_number WithEnd:[NSString stringWithFormat:@"%@",_model[@"tradeNo"]] withresult:@"" withColor:[UIColor blackColor] withFont:14 withbaseColor:[CXSinglerModel colorWithHex:@"9A9A9A" alpha:1]];
    [self loadlabel:_dealMoney WithEnd:[NSString stringWithFormat:@"￥%.2lf",[_model[@"price"] floatValue] / 100] withresult:@"" withColor:[UIColor blackColor] withFont:14 withbaseColor:[UIColor blackColor]];
    [self loadlabel:_weixinMoney WithEnd:[NSString stringWithFormat:@"￥%.2lf",[_model[@"payAmount"] floatValue] / 100 ] withresult:@"" withColor:[UIColor blackColor] withFont:14 withbaseColor:[UIColor blackColor]];
    [self loadlabel:_integralMoney WithEnd:[NSString stringWithFormat:@"(￥%.2lf)",[_model[@"payIntegral"] floatValue] / 100] withresult:[NSString stringWithFormat:@"%@积分",_model[@"payIntegral"]] withColor:[CXSinglerModel colorWithHex:@"F5A623" alpha:1] withFont:14 withbaseColor:[UIColor blackColor]];
    NSString *end = @"";
    UIColor *basecolor = [UIColor blackColor];
//    [NSString stringWithFormat:@"￥%.2lf",[_model[@"discount"] floatValue] / 100]
    if ([_model[@"discount"] integerValue] == 0) {
    }
    else{
        end = @"(抵扣券)";
        basecolor = [CXSinglerModel colorWithHex:@"FE4438" alpha:1];
    }
    CGFloat partPriceNum = [_model[@"discount"] floatValue];
    NSString *partPricestr = @"";
    if (partPriceNum == 0) {
        partPricestr = [NSString stringWithFormat:@"￥%.2lf",[_model[@"discount"] floatValue]];
    }
    else{
        partPricestr = [NSString stringWithFormat:@"-￥%.2lf",[_model[@"discount"] floatValue]];
    }
    [self loadlabel:_partPrice WithEnd:end withresult:partPricestr withColor:basecolor withFont:14 withbaseColor:[UIColor blackColor]];
    _status.text = @"交易成功";
    [_header sd_setImageWithURL:[NSURL URLWithString:_model[@"avatar"]]];
    _money.text = [NSString stringWithFormat:@"+%.2lf",[_model[@"totalAmount"] floatValue] / 100];
    _money.textColor = [CXSinglerModel colorWithHex:@"0EBF66" alpha:1];
}



/**
 上级传入订单信息

 @param info 订单信息
 */
-(void)loadWithInfo:(NSMutableDictionary *)info{
    _model = info;
    [self viewLoad];
//    [self loadlabel:_name WithEnd:[NSString stringWithFormat:@"%@",info[@"tradeNo"]]info[@"userName"] withresult:@"" withColor:[UIColor blackColor] withFont:14 withbaseColor:[UIColor blackColor]];
//    [self loadlabel:_name WithEnd:[NSString stringWithFormat:@"%@",info[@"tradeNo"]]info[@"userName"] withresult:@"" withColor:[UIColor blackColor] withFont:14 withbaseColor:[UIColor blackColor]];
    
}

-(void)loadlabel:(UILabel *)baselabel WithEnd:(NSString *)end withresult:(NSString *)result withColor:(UIColor *)lightColor withFont:(NSInteger)fontSize withbaseColor:(UIColor *)baseColor{
    NSMutableAttributedString *allword = [[NSMutableAttributedString alloc] initWithString:[result stringByAppendingString:end]];
    [allword addAttribute:NSForegroundColorAttributeName value:baseColor range:NSMakeRange(0, allword.length)];
    [allword addAttribute:NSForegroundColorAttributeName value:lightColor range:NSMakeRange(0, result.length)];
    baselabel.attributedText = allword;
    NSLog(@"-=-=-=-=-=-=-=-=-=-=-%@",allword);
    baselabel.font = [UIFont systemFontOfSize:fontSize];
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
